package LeetCode.leetcode28;

import java.util.HashMap;

public class Review1 {
    public int strStr(String haystack, String needle) {
        HashMap<String,Integer> map = new HashMap<>();
        int m = haystack.length(), n = needle.length();
        if (n == 0) return 0;
        for (int i = 0; i <= m - n; i++) {
            String sub = haystack.substring(i, i + n);
            map.putIfAbsent(sub, i);
        }
        return map.getOrDefault(needle, -1);
    }
}
